package net.bac.sbe.common.xml.helper;

import java.io.InputStream;
import java.util.logging.Level;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import net.bac.sbe.common.logger.LoggerService;

public final class MarshallHelper {
	
	private MarshallHelper(){
		
	}
	
	public static <T> T marshall (Class<T> expectedObject, InputStream is){
		T result = null;
		try {
			JAXBContext jc = JAXBContext.newInstance( expectedObject.getPackage().getName());
			Unmarshaller m = jc.createUnmarshaller();
			result = ((JAXBElement<T>)m.unmarshal(is)).getValue();
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			LoggerService.logException(Level.SEVERE, "ERROR:", e);
		}
		return result;
	}
}
